package com.example.xihuashoujiduan.activity

import android.util.Patterns
import android.widget.Toast
import androidx.core.text.HtmlCompat
import com.example.xihuashoujiduan.R
import com.example.xihuashoujiduan.base.BaseActivity
import com.example.xihuashoujiduan.databinding.ActivitySaomajiaguoBinding
import com.example.xihuashoujiduan.viewmodel.Mainviewmodel
import java.util.regex.Pattern

class SaomajiaguoActivity :BaseActivity<Mainviewmodel, ActivitySaomajiaguoBinding>(R.layout.activity_saomajiaguo){
    override fun initView() {
        val jieguo= intent.getStringExtra("result")

//        if (jieguo != null) {
//            when {
//                isImageUrl(jieguo) -> {
//                    binding.jieguo.text = HtmlCompat.fromHtml("<img src=\"$jieguo\"/>", HtmlCompat.FROM_HTML_MODE_LEGACY)
//                    Toast.makeText(this, "这是一个图片链接", Toast.LENGTH_SHORT).show()
//                }
//                isVideoUrl(jieguo) -> {
//                    binding.jieguo.text = HtmlCompat.fromHtml("<video controls src=\"$jieguo\"/>", HtmlCompat.FROM_HTML_MODE_LEGACY)
//                    Toast.makeText(this, "这是一个视频链接", Toast.LENGTH_SHORT).show()
//                }
//                Patterns.WEB_URL.matcher(jieguo).matches() -> {
//                    binding.jieguo.text = HtmlCompat.fromHtml("<a href=\"$jieguo\">点击访问链接</a>", HtmlCompat.FROM_HTML_MODE_LEGACY)
//                    Toast.makeText(this, "这是一个网页链接", Toast.LENGTH_SHORT).show()
//                }
//                else -> {
//                    binding.jieguo.text = jieguo
//                    Toast.makeText(this, "无法识别的链接类型", Toast.LENGTH_SHORT).show()
//                }
//            }
//        } else {
//            binding.jieguo.text = "未获取到结果"
//        }


       binding.jieguo.text=jieguo

    }

//    private fun isImageUrl(url: String): Boolean {
//        val imagePattern = Pattern.compile(
//            Patterns.WEB_URL.pattern() + "\\.(png|jpg|jpeg|gif|bmp|webp)$",
//            Pattern.CASE_INSENSITIVE
//        )
//        return imagePattern.matcher(url).matches()
//    }
//
//    private fun isVideoUrl(url: String): Boolean {
//        val videoPattern = Pattern.compile(
//            Patterns.WEB_URL.pattern() + "\\.(mp4|avi|mov|mkv|flv|wmv|webm)$",
//            Pattern.CASE_INSENSITIVE
//        )
//        return videoPattern.matcher(url).matches()
//    }
    override fun dataObservese() {

    }
}